#!/bin/bash
echo -e "\033[1;44m[script] Start my script!\033[0m"

# 定义取消挂载函数和杀死进程函数
cleanup() {
    echo -e "\033[1;44m[script] Cleaning up...\033[0m"
    umount /mnt/myusb  			   # 取消挂载U盘
    kill $v4l2_pid $makevideo_pid  # 杀死已启动的进程
}

# 挂载U盘
mount /dev/sda1 /mnt/myusb
echo -e "\033[1;44m[script] Mount USB flash disk success!\033[0m"

# 运行v4l2
/root/network-camera/qt/v4l2 -platform linuxfb &
v4l2_pid=$!
echo -e "\033[1;44m[script] v4l2 pid=$v4l2_pid\033[0m"

# 运行makevideo
/root/network-camera/makevideo &
makevideo_pid=$!
echo -e "\033[1;44m[script] makevideo pid=$makevideo_pid\033[0m"

# 退出的清理操作
trap cleanup EXIT

# 等待脚本结束
wait
